require 'osx/cocoa'
include OSX

class VectorController < NSObject
  ib_outlet :graph
  ib_outlet :angle
  ib_outlet :length
  
  attr_accessor :vector
  attr_accessor :origin
  attr_accessor :color
  
  def initialize
    @origin = Point.new(0, 20)
    @vector = Vector.new(500, 0)
    @color = NSColor.whiteColor
  end
  
  def awakeFromNib
    updateView
  end
  
  ib_action :angle_changed do |sender|
    @vector.angle = sender.integerValue
    @angle.stringValue = "Angle: #{@vector.angle}"
    NSLog("Angle changed to #{@vector.angle}")
    updateView
  end
  
  ib_action :length_changed do |sender|
    @vector.length = sender.integerValue
    @length.stringValue = "Length: #{@vector.length}"
    log("Length changed to #{@vector.length}")
    updateView
  end
  
  ib_action :color_changed do |sender|
    @color = sender.color
    updateView
  end
  
  ib_action :reset do |sender|
    @origin = Point.new(0, 0)
    @vector = Vector.new(0, 0)
    updateView
  end
  
  def updateView
    log("Graph update")
    @graph.update
  end
end